﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace _039.反射
{
	internal class Program
	{
		static void Main(string[] args)
		{
			// 反射
			// Type 类
			// 每一个类都有唯一的type对象
			//Type type = typeof(MyClass);
			MyClass my = new MyClass();
			Type type = my.GetType();

			Console.WriteLine(type.Name);
			Console.WriteLine(type.Namespace);
			// 程序集
			Console.WriteLine(type.Assembly);
			// 得到所有的公有字段
			FieldInfo[] fieldInfos = type.GetFields();
			foreach (FieldInfo fieldInfo in fieldInfos)
			{
				//Console.WriteLine(fieldInfo);
				Console.WriteLine(fieldInfo.Name);
			}
			// 得到所有的公有属性
			PropertyInfo[] propertyInfos = type.GetProperties();
			foreach (PropertyInfo propertyInfo in propertyInfos)
			{
				//Console.WriteLine(propertyInfo);
				Console.WriteLine(propertyInfo.Name);
			}
			Console.WriteLine("------------");

			// 得到所有的公有方法
			MethodInfo[] methodInfos = type.GetMethods();
			foreach (MethodInfo methodInfo in methodInfos)
			{
				//Console.WriteLine(methodInfo);
				Console.WriteLine(methodInfo.Name);
			}

		}
	}
}
